package com.codedancer.campus.po;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.codedancer.campus.common.typehandler.CodeEnumTypeHandler;
import com.codedancer.campus.enums.CircleStatus;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gitee.sunchenbin.mybatis.actable.annotation.Column;
import com.gitee.sunchenbin.mybatis.actable.annotation.Table;
import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant;
import java.io.Serializable;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@TableName(value = "circle", autoResultMap = true)
@Table(name = "circle", comment = "圈子")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Circle extends Model<Circle> implements Serializable {

    @TableId
    @TableField("uuid")
    @Column(name = "uuid", type = MySqlTypeConstant.VARCHAR, length = 36, isKey = true, isNull = false, comment = "uuid")
    private String uuid;

    @TableField("title")
    @Column(name = "title", type = MySqlTypeConstant.VARCHAR, length = 16, isNull = false, comment = "标题")
    private String title;

    @TableField("description")
    @Column(name = "description", type = MySqlTypeConstant.VARCHAR, length = 128, isNull = false, comment = "描述")
    private String description;

    @TableField("avatar")
    @Column(name = "avatar", type = MySqlTypeConstant.VARCHAR, length = 128, isNull = false, comment = "圈子头像")
    private String avatar;

    @TableField("disabled")
    @Column(name = "disabled", type = MySqlTypeConstant.BIT, isNull = false, comment = "是否禁用", defaultValue = "true")
    private Boolean disabled;

    @TableField(value = "status", typeHandler = CodeEnumTypeHandler.class)
    @Column(name = "status", type = MySqlTypeConstant.TINYINT, length = 1, isNull = false, comment = "圈子状态 1表示待审核 2表示未通过 3表示已通过")
    private CircleStatus status;

    @TableField("deleted")
    @Column(name = "deleted", type = MySqlTypeConstant.TINYINT, length = 1, isNull = false, comment = "是否删除 1表示删除 0表示未删除", defaultValue = "0")
    private Short deleted;

    @TableField("create_user_uuid")
    @Column(name = "create_user_uuid", type = MySqlTypeConstant.VARCHAR, length = 36, isNull = false, comment = "创建人uuid")
    private String createUserUuid;

    @TableField("create_school_uuid")
    @Column(name = "create_school_uuid", type = MySqlTypeConstant.VARCHAR, length = 36, isNull = false, comment = "创建学校uuid")
    private String createSchoolUuid;

    @Column(name = "create_time", type = MySqlTypeConstant.DATETIME, isNull = false, comment = "创建时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Column(name = "update_time", type = MySqlTypeConstant.DATETIME, isNull = false, comment = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @TableField("view_count")
    @Column(name = "view_count", type = MySqlTypeConstant.INT, length = 10, isNull = false, comment = "浏览量", defaultValue = "0")
    private Integer viewCount;

    @TableField("follow_count")
    @Column(name = "follow_count", type = MySqlTypeConstant.INT, length = 10, isNull = false, comment = "关注量", defaultValue = "0")
    private Integer followCount;

    @TableField("examine_count")
    @Column(name = "examine_count", type = MySqlTypeConstant.INT, length = 10, isNull = false, comment = "审核次数最多5次", defaultValue = "0")
    private Integer examineCount;

    /**
     * 审核次数是否超过5次
     * @return
     */
    public boolean examineCountIsGtFive(){
        return examineCount >= 5;
    }
}
